package com.example.todo_list;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.graphics.ColorSpace;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import org.litepal.LitePal;
import org.litepal.tablemanager.Connector;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<todo_list_item> templist = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        setContentView(R.layout.activity_main);
        RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycle_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        Myadapter tempadapter = new Myadapter(MainActivity.this,templist);
        recyclerView.setAdapter(tempadapter);
        Connector.getDatabase();



        Button add_button = (Button)findViewById(R.id.add);

        add_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(MainActivity.this,add_something_todo.class);
                startActivity(intent1);
                MainActivity.this.finish();
            }
        });




    }

    void init(){
        templist.clear();
        List<todolist> list_for_databases = LitePal.findAll(todolist.class);
        for(todolist t : list_for_databases){
            String tempstr = t.getMessage();
            int tempcheck = t.getIs_check();
            int time = t.getNumber();
            todo_list_item temp_for_templist = new todo_list_item(tempstr,tempcheck,time);
            templist.add(temp_for_templist);

        }
    }
}